<template>
  <div class="page">
    <el-form label-width="80px" inline :model="searchFrom">
      <el-form-item label="编号">
        <el-input v-model="searchFrom.cmbbh"></el-input>
      </el-form-item>
      <el-form-item label="单名">
        <el-input v-model="searchFrom.cmbmc"></el-input>
      </el-form-item>
      <el-form-item label="分类">
        <el-input v-model="searchFrom.csfxmmc"></el-input>
      </el-form-item>
      <el-form-item label="项目名称">
        <el-input v-model="searchFrom.cztmc"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="getHisProject">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column
        prop="cmbbh"
        label="编号"
        sortable
        width="180">
      </el-table-column>
      <el-table-column
        prop="cmbmc"
        label="单名"
        sortable
        width="180">
      </el-table-column>
      <el-table-column
        prop="csfxmmc"
        label="分类"
        sortable
        width="180">
      </el-table-column>
      <el-table-column
        prop="cztmc"
        label="项目名称">
      </el-table-column>
      <el-table-column
        label="状态"
        width="150">
        <template slot-scope="{row}">
          <el-switch
            v-model="row.status"
            :active-value="0"
            :inactive-value="1"
            active-text="启用"
            inactive-text="禁用"
            @change="updateHisProject(row)">
          </el-switch>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="pageSizeChange"
      @current-change="pageNoChange"
      :current-page.sync="page.pageNo"
      :page-size="page.pageSize"
      layout="total, prev, pager, next"
      :total="page.total">
    </el-pagination>
  </div>
</template>

<script>
import { getHisProject, updateHisProject } from '@/api/official/official'
export default {
  name: 'InternetHospitalMangeSmartGuide',

  data() {
    return {
      searchFrom: {},
      page:{
        total:0,
        pageSize:10,
        pageNo:1,
      },
      tableData: [],
    };
  },

  mounted() {
    this.getHisProject()
  },

  methods: {
    getHisProject() {
      getHisProject({...this.searchFrom}, {pageIndex: this.page.pageNo, pageSize: this.page.pageSize}).then(res => {
        this.tableData = res.records
        this.page.total = res.total
      })
    },
    updateHisProject(row) {
      console.log(row)
      const data = [
        {
          id: row.id,
          status: row.status
        }
      ]
      updateHisProject(data).then(res => {
        console.log(res)
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.getHisProject()
      })
    },
    pageSizeChange(val){
      this.page.pageSize = val;
      this.getHisProject();
    },
    pageNoChange(val){
      this.page.pageNo = val;
      this.getHisProject();
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  padding: 24px;
}
</style>